package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.generator.entity.TblDifficultPersonnelEntity;
import io.renren.modules.generator.service.TblDifficultPersonnelService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-12-18 14:10:39
 */
@RestController
@Api(tags = "数据采集加工模块", value = "数据采集加工模块")
@RequestMapping("generator/tbldifficultpersonnel")
public class TblDifficultPersonnelController {
    @Autowired
    private TblDifficultPersonnelService tblDifficultPersonnelService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("数据采集录入列表")
    public R list(@RequestParam String curPage, @RequestParam String limit, String param) {
        Map map = new HashMap<String, String>();
        map.put("curPage", curPage);
        map.put("limit", limit);
        map.put("param", param);
        LambdaQueryWrapper<TblDifficultPersonnelEntity> wrapper = Wrappers.<TblDifficultPersonnelEntity>query().lambda();
        wrapper.eq(TblDifficultPersonnelEntity::getStatus,0)
                .or().eq(TblDifficultPersonnelEntity::getIdCard,map.get("param"))
                .or().eq(TblDifficultPersonnelEntity::getName,map.get("param"));
        PageUtils page = tblDifficultPersonnelService.queryPage(map,wrapper);
        return R.ok().put("page", page);
    }

    @GetMapping("/filList")
    @ApiOperation("已核对列表")
    public R filList(@RequestParam String curPage, @RequestParam String limit, String param) {
        Map map = new HashMap<String, String>();
        map.put("curPage", curPage);
        map.put("limit", limit);
        map.put("param", param);
        LambdaQueryWrapper<TblDifficultPersonnelEntity> wrapper = Wrappers.<TblDifficultPersonnelEntity>query().lambda();
        wrapper.eq(TblDifficultPersonnelEntity::getStatus,4)
                .or().eq(TblDifficultPersonnelEntity::getIdCard,map.get("param"))
                .or().eq(TblDifficultPersonnelEntity::getName,map.get("param"));
        PageUtils page = tblDifficultPersonnelService.queryPage(map,wrapper);
        return R.ok().put("page", page);
    }



    @GetMapping("/yichaList")
    @ApiOperation("已核查列表")
    public R yichaList(@RequestParam String curPage, @RequestParam String limit, String param) {
        Map map = new HashMap<String, String>();
        map.put("curPage", curPage);
        map.put("limit", limit);
        map.put("param", param);
        LambdaQueryWrapper<TblDifficultPersonnelEntity> wrapper = Wrappers.<TblDifficultPersonnelEntity>query().lambda();
        wrapper.eq(TblDifficultPersonnelEntity::getStatus,1)
                .or().eq(TblDifficultPersonnelEntity::getIdCard,map.get("param"))
                .or().eq(TblDifficultPersonnelEntity::getName,map.get("param"));
        PageUtils page = tblDifficultPersonnelService.queryPage(map,wrapper);
        return R.ok().put("page", page);
    }

    @GetMapping("/butongguo")
    @ApiOperation("未通过列表")
    public R butongguo(@RequestParam String curPage, @RequestParam String limit, String param) {
        Map map = new HashMap<String, String>();
        map.put("curPage", curPage);
        map.put("limit", limit);
        map.put("param", param);
        LambdaQueryWrapper<TblDifficultPersonnelEntity> wrapper = Wrappers.<TblDifficultPersonnelEntity>query().lambda();
        wrapper.eq(TblDifficultPersonnelEntity::getStatus,2)
                .or().eq(TblDifficultPersonnelEntity::getIdCard,map.get("param"))
                .or().eq(TblDifficultPersonnelEntity::getName,map.get("param"));
        PageUtils page = tblDifficultPersonnelService.queryPage(map,wrapper);
        return R.ok().put("page", page);
    }

    @GetMapping("/shangbao")
    @ApiOperation("未通过列表")
    public R shangbao(@RequestParam String curPage, @RequestParam String limit, String param) {
        Map map = new HashMap<String, String>();
        map.put("curPage", curPage);
        map.put("limit", limit);
        map.put("param", param);
        LambdaQueryWrapper<TblDifficultPersonnelEntity> wrapper = Wrappers.<TblDifficultPersonnelEntity>query().lambda();
        wrapper.eq(TblDifficultPersonnelEntity::getStatus,3)
                .or().eq(TblDifficultPersonnelEntity::getIdCard,map.get("param"))
                .or().eq(TblDifficultPersonnelEntity::getName,map.get("param"));
        PageUtils page = tblDifficultPersonnelService.queryPage(map,wrapper);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("数据采集录入详情")
    public R info(@PathVariable("id") Integer id) {
        TblDifficultPersonnelEntity tblDifficultPersonnel = tblDifficultPersonnelService.getById(id);
        return R.ok().put("tblDifficultPersonnel", tblDifficultPersonnel);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("数据采集录入")
    public R save(@RequestBody TblDifficultPersonnelEntity tblDifficultPersonnel) {
        tblDifficultPersonnel.setCreateTime(new Date());
        tblDifficultPersonnelService.save(tblDifficultPersonnel);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改数据采集")
    public R update(@RequestBody TblDifficultPersonnelEntity tblDifficultPersonnel) {
        tblDifficultPersonnelService.updateById(tblDifficultPersonnel);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/hedui")
    @ApiOperation("核对数据接口")
    public R hedui(@RequestBody Integer[] ids) {
        for (int i = 0; i < ids.length; i++) {
            TblDifficultPersonnelEntity tblDifficultPersonnelEntity = new TblDifficultPersonnelEntity();
            tblDifficultPersonnelEntity.setId(ids[i]);
            tblDifficultPersonnelEntity.setStatus(4);
            tblDifficultPersonnelService.updateById(tblDifficultPersonnelEntity);
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/hecha")
    @ApiOperation("核查数据接口")
    public R hecha(@RequestBody Integer[] ids) {
        for (int i = 0; i < ids.length; i++) {
            TblDifficultPersonnelEntity tblDifficultPersonnelEntity = new TblDifficultPersonnelEntity();
            tblDifficultPersonnelEntity.setId(ids[i]);
            tblDifficultPersonnelEntity.setStatus(1);
            tblDifficultPersonnelService.updateById(tblDifficultPersonnelEntity);
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/butongguo")
    @ApiOperation("不通过 数据接口")
    public R butongguo(@RequestBody Integer[] ids) {
        for (int i = 0; i < ids.length; i++) {
            TblDifficultPersonnelEntity tblDifficultPersonnelEntity = new TblDifficultPersonnelEntity();
            tblDifficultPersonnelEntity.setId(ids[i]);
            tblDifficultPersonnelEntity.setStatus(2);
            tblDifficultPersonnelService.updateById(tblDifficultPersonnelEntity);
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/shangbao")
    @ApiOperation("上报数据接口")
    public R shangbao(@RequestBody Integer[] ids) {
        for (int i = 0; i < ids.length; i++) {
            TblDifficultPersonnelEntity tblDifficultPersonnelEntity = new TblDifficultPersonnelEntity();
            tblDifficultPersonnelEntity.setId(ids[i]);
            tblDifficultPersonnelEntity.setStatus(3);
            tblDifficultPersonnelService.updateById(tblDifficultPersonnelEntity);
        }
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除数据采集")
    public R delete(@RequestBody Integer[] ids) {
        tblDifficultPersonnelService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
